home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_300
/
352_01
/
dblib.h
< prev
next >
Wrap
C/C++ Source or Header
|
1991-05-04
|
27KB
|
820 lines
#ifndef DBLIB_HEADER
#define DBLIB_HEADER
#include "wtwg.h"
#include "string.h"
#include <iostream.h>
#include <alloc.h>
#include <dos.h>
/* farmemcpy()
* in large models this is just memcpy
* but in small models it's movedata()
*/
#undef LARGE_DATA_MODEL
#ifdef __LARGE__
#define LARGE_DATA_MODEL
#endif
#ifdef __COMPACT__
#define LARGE_DATA_MODEL
#endif
#ifdef __HUGE__
#define LARGE_DATA_MODEL
#endif
#ifdef LARGE_DATA_MODEL
#define farmemcpy(aa,bb,cc) memcpy (aa,bb,cc)
#else
/* model is small or medium - need a far * equivalent of
* memcpy, write, read, memcmp
*/
#define farmemcpy(dest,src,num) \
movedata (FP_SEG(src), FP_OFF(src), FP_SEG(dest), FP_OFF(dest), num )
#endif /* memcpy */
// min & max. - these are undefined in TurboC++
#ifndef min
#define min(x,y) (( (x) < (y) ) ? (x) : (y))
#endif
#ifndef max
#define max(x,y) (( (x) > (y) ) ? (x) : (y))
#endif
/* array index routines.
*
* roll_up, roll_down
* returns the next/prev index to an array of max items
* arranged in a circle 0 -> 1 -> 2 -> ... -> max -> 0 etc...
* inch_up, inch_down
* increases or decreases the index but stays within array bounds
*/
#define roll_up(n, max) ( (n) == (max)-1 ? 0 : (n)+1 )
#define roll_down(n, max) ( (n) == 0 ? (max)-1 : (n)-1 )
#define inch_up(n, max) ( (n) == (max)-1 ? (n) : (n)+1 )
#define inch_down(n, max) ( (n) == 0 ? 0 : (n)-1 )
// NORMALIZE macros.
// Far pointer normalization routine
// Arithmetic on far pointers only affects the offset,
// does not carry into the segment portion.
// to avoid overflow errors,
// must convert seg:off pair to place as much
// of the address as possible into the segment part.
//
// NORMALIZE () - unconditionally normalize a far pointer.
// _NORMALIZE () - normalize a data pointer IF memory model requires it
//
// use _NORMALIZE for pointers not explicitly declared far.
//
// NOTE: MODIFIED FOR C++ which must cast the result to the appropriate type
//
#define NORMALIZE(fp, type) \
fp = (type) MK_FP ( ( FP_SEG(fp) + (FP_OFF(fp)>>4) ), \
((unsigned)(FP_OFF(fp))& 0x000f) )
#ifdef __COMPACT__
#define _NORMALIZE(fp,type) NORMALIZE(fp,type)
#endif
#ifdef __LARGE__
#define _NORMALIZE(fp,type) NORMALIZE(fp,type)
#endif
#ifdef __SMALL__
#define _NORMALIZE(fp,type)
#endif
#ifdef __MEDIUM__
#define _NORMALIZE(fp,type)
#endif
#ifdef __HUGE__
#define _NORMALIZE(fp,type)
#endif
/* the next set of definitions allow use of Turbo C's ability to
* generate in-line interrupts, while maintaining compatibility
* with compilers that have an int86() function and a union REGS.
*
* To use this technique, ALWAYS load the registers in inverse
* alphabetical order (DX first, then CX, BX and AX last)
* and don't try to do any complex computations in the lines
* that access the registers.
* WRONG, for 3 reasons:
* _AH = 1;
* _DX = value1 + 3*value2; ===> TurboC uses AX
* geninterrupt ( variable_int_number ); ditto
* RIGHT, but useless:
* value3 = value1 + 3*value2;
* if ( int_number = 0x01 )
* {
* _DX = value3;
* _AX = 1;
* geninterrupt ( 0x01 );
* }
* else {
* _DX = value3;
* _AX = 1;
* geninterrupt ( 0x02 );
* }
*
*/
#ifndef __TURBOC__
#define PSEUDOREGS union REGS regs;
#define _AX regs.x.ax
#define _AL regs.h.al
#define _AH regs.h.ah
#define _BX regs.x.bx
#define _BL regs.h.bl
#define _BH regs.h.bh
#define _CX regs.x.cx
#define _CL regs.h.cl
#define _CH regs.h.ch
#define _DX regs.x.dx
#define _DL regs.h.dl
#define _DH regs.h.dh
#define _FLAGS regs.x.flags
#define geninterrupt(intno) int86((intno), ®s, ®s)
#else
#define PSEUDOREGS
#endif /* end of redifinning pseudoregs and interrupts */
// generate inport and outport instructions inline
// temp. fix pending TURBOC++ upgrade.
#ifndef outportb
#define outportb(portid, value) __outportb__( (portid), (value) )
void _Cdecl __outportb__(int __portid, unsigned char __value);
#endif
#ifndef inportb
#define inportb(portid) __inportb__( (portid) )
unsigned char _Cdecl __inportb__(int __portid);
#endif
// wmatherr() -
// a routine to trap integer and floating point math errors.
// prevents program from crashing, which would leave system...
// in bizarre video modes, with expanded memory allocated, etc...
// SOURCE: wmatherr.cpp
void wmatherr (void);
// STRINGPP.H - a string class for TurboC++
//
// D Blum 8/90
//
class String {
public:
static char caseSens; // default = OFF any NONZERO is ON
private:
int n; // strlen = numbytes not counting \0
char *s; // the string.
void construct ( char *p ); // local utility for construction
void destruct ( ); // local utility for destruction
// source for both: STRPP.CPP
// Utility functions called by functions in String::
// the utilities include copy, comparison, scanning, allocation
// // source files:
static int cmp (char *a, char *b); // STRPPCMP.CPP
static int memcmp (char *a, char *b, int nb); // STRPPMCP.CPP
static int chrcmp ( char a, char b ); // STRPPCHC.CPP
static int findstr ( char *a, int na, char *b );// STRPPFNS.CPP
static int findchr ( char *a, int na, char c ); // STRPPFNC.CPP
void strpad ( ); // STRPPPAD.CPP
void slide ( int start, int stop ); // STRPPSLD.CPP
public:
// Constructors: make String from a String, a char *ptr, or a char
// also can make fixed length strings.
String() { n=0; s=NULL;};
String(int); // make a fixed len String
// init to all spaces.
// source: STRPPFIX.CPP
String ( char *ptr ){n = strlen (ptr); construct (ptr); };
String ( String& str ){ n= str.n; construct ( str.s ); };
// Copy constructor utility.
private: void copy( int l, char *p ); // source: STRPP.CPP
public:
void assign ( char *data ); // assign ownership of data
// data MUST have been malloc'd
// and will be free'd by String
// BE CAREFULL !!!!!
// STRPPASN.CPP
String& operator=(String& source)
{
copy ( source.n, source.s );
return *this;
}; // end assignemt operator
String& operator=(char *ptr)
{
copy ( strlen(ptr), ptr );
return *this;
};
String& operator= (char c)
{
copy ( 1, &c );
return *this;
};
// Destructor
~String ( ) {destruct();}; // source: STRPP.CPP
// comparison operators.
friend int operator==(String& a, String &b)
{return (String::cmp (a.s, b.s)==0);};
friend int operator>=(String& a, String &b)
{return (String::cmp (a.s, b.s)>=0);};
friend int operator<=(String& a, String &b)
{return (String::cmp (a.s, b.s)<=0);};
friend int operator>(String& a, String &b)
{return (String::cmp (a.s, b.s)>0);};
friend int operator<(String& a, String &b)
{return (String::cmp (a.s, b.s)<0);};
friend int operator==(char *a, String &b)
{return (String::cmp (a, b.s)==0);};
friend int operator>=(char *a, String &b)
{return (String::cmp (a, b.s)>=0);};
friend int operator<=(char *a, String &b)
{return (String::cmp (a, b.s)<=0);};
friend int operator>(char *a, String &b)
{return (String::cmp (a, b.s)>0);};
friend int operator<(char *a, String &b)
{return (String::cmp (a, b.s)<0);};
friend int operator==(String& a, char *b)
{return (String::cmp (a.s, b)==0);};
friend int operator>=(String& a, char *b)
{return (String::cmp (a.s, b)>=0);};
friend int operator<=(String& a, char *b)
{return (String::cmp (a.s, b)<=0);};
friend int operator>(String& a, char *b)
{return (String::cmp (a.s, b)>0);};
friend int operator<(String& a, char *b)
{return (String::cmp (a.s, b)<0);};
// CONCATENAT